package com.lc.cehui.ui.activity.mine;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.hjq.toast.ToastUtils;
import com.lc.cehui.R;
import com.lc.cehui.app.AppActivity;
import com.lc.cehui.http.glide.GlideApp;
import com.lc.cehui.util.SettingBar;
import com.lc.cehui.widget.GlideEngine;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.tbruyelle.rxpermissions2.RxPermissions;

import java.io.File;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.functions.Consumer;

/**

 * desc   : 个人资料
 */
public final class PersonalDataActivity extends AppActivity {


    @BindView(R.id.iv_person_data_avatar)
    AppCompatImageView mAvatarView;
    @BindView(R.id.sb_person_data_name)
    SettingBar sbPersonDataName;
    @BindView(R.id.sb_person_data_id)
    SettingBar sbPersonDataId;
    @BindView(R.id.sb_person_data_vx)
    SettingBar sbPersonDataVx;
    /**
     * 头像地址
     */
    private String mAvatarUrl;
    private RxPermissions rxPermissions;

    @Override
    protected int getLayoutId() {
        return R.layout.personal_data_activity;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        GlideApp.with(getActivity())
                .load(R.drawable.image11)
                .placeholder(R.drawable.image11)
                .error(R.drawable.image11)
                .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                .into(mAvatarView);




    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        rxPermissions = new RxPermissions(this);
    }
    private void carem() {
        rxPermissions
                .request(Manifest.permission.CAMERA)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        if (aBoolean) {
                            PictureSelector.create(PersonalDataActivity.this)
                                    .openGallery(PictureMimeType.ofImage())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                                    .maxSelectNum(1)
                                    .imageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项
                                    .imageSpanCount(4)// 每行显示个数
                                    .selectionMode(PictureConfig.SINGLE)// 多选 or 单选PictureConfig.MULTIPLE : PictureConfig.SINGLE
                                    .isCamera(true)// 是否显示拍照按钮
                                    .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
//                                    .isEnableCrop(true)
//                                    .withAspectRatio(1, 1)// 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
                                    .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
                        } else {
                            ToastUtils.show("请求权限失败,相机不可用");
                        }
                    }
                });
    }
    @OnClick({R.id.iv_person_data_avatar, R.id.sb_person_data_name, R.id.sb_person_data_id, R.id.sb_person_data_vx})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_person_data_avatar:
                carem();
                break;
            case R.id.sb_person_data_name:
                break;
            case R.id.sb_person_data_id:
                break;
            case R.id.sb_person_data_vx:
                break;
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
            File headFile = new File(selectList.get(0).getRealPath());
//            getCommon_uploads(headFile);


        }
    }
}